//
// Created on 2024/1/22.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef test_napi_utils_H
#define test_napi_utils_H

#include "napi/native_api.h"
#include <ace/xcomponent/native_interface_xcomponent.h>
#include <cmath>
#include <cstdint>
#include <rawfile/raw_file_manager.h>
#include <unordered_map>

class napiUtils {
private:
    static std::unordered_map<std::string, OH_NativeXComponent *> nativeXComponentMap_;

public:
    static napi_value loadNapiArgs(napi_env env, napi_callback_info info);
    static napi_value createStringNapi(napi_env env, const char *value);
    static napi_value createIntNapi(napi_env env, int32_t value);
    static napi_value createLongNapi(napi_env env, int64_t value);
    static napi_value createDoubleNapi(napi_env env, double value);
    static napi_value createArrayNapi(napi_env env, int length);
    static napi_value createArrayNapi(napi_env env);

    static char *loadNapiString(napi_env env, napi_value value);
    static bool loadNapiInt(napi_env env, napi_value value, int32_t* data);
    static bool loadNapiDouble(napi_env env, napi_value value, double_t* data);
    static bool loadNapiLong(napi_env env, napi_value value, int64_t* data);

    static napi_ref loadNapiRef(napi_env env, napi_value value);

    static napi_value createUint8Array(napi_env env, uint8_t *bytes, int size);

    static uint8_t *loadNapiUint8Arrays(napi_env env, napi_value value);

    static char *readRawFileContent(NativeResourceManager *manager, const char *path);

    static uint8_t *rotationAngle(uint8_t *inData, int width, int height, int orientation, int *isUseFree);
};

#endif // test_napi_utils_H
